﻿@model ProjectunitViewModel
@{
    Layout = null;
    ViewBag.Title = "人员查询标段选择弹出框";
}
<div class="pageContent" layouth="38">
    <form method="post" id="from_unit" action="demo/common/ajaxDone.html" class="pageForm required-validate"
    onsubmit="return validateCallback(this,dialogAjaxDone)">
    <ul id="rygl_rycx_zTree" class="ztree">
    </ul>
    </form>
</div>
<div class="formBar">
    <ul>
        <li>
            <button type="button" class="btn btn-success btn-sm" onclick="unitSel()">
                选择</button>
        </li>
        <li>
            <button type="button" class="close btn btn-default btn-sm">
                取消</button>
        </li>
    </ul>
</div>
<script type="text/javascript">
    var rygl_rycx_zTree;
    var setting = {
        treeObjId: "rygl_rycx_zTree",
        isSimpleData: true,              //数据是否采用简单 Array 格式，默认false
        treeNodeKey: "id",               //在isSimpleData格式下，当前节点id属性
        treeNodeParentKey: "pId",        //在isSimpleData格式下，当前节点的父节点id属性
        showLine: true,                  //是否显示节点间的连线
        checkable: true,                 //每个节点上是否显示 CheckBox
        callback: {
            nodeCreated: rygl_rycx_zTree_creat    //这是节点生成时的回调函数
        }
    };
    function rygl_rycx_zTree_creat(event, treeId, treeNode) {
        var section = $("#rygl_rycx_section").val();
        if (section.indexOf(treeNode.id) >= 0 && treeNode.pId != null) {
            treeNode.checked = true;
            rygl_rycx_zTree.updateNode(treeNode, true);
        }
    }
    $(function () {
        $.getJSON(
           "/PersonnelLog/ProjectSegment/GetAllSegmentJson",
           function (data) {
               rygl_rycx_zTree = $("#rygl_rycx_zTree").zTree(setting, data);
               rygl_rycx_zTree.expandAll(true);
           });
    });

    function unitSel() {
        var unitCodes = "";
        var nodes = rygl_rycx_zTree.getCheckedNodes(true);
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].pId != null) {
                unitCodes += nodes[i].id + ",";
            }
        }
        $("#rygl_rycx_section").val(unitCodes);
        $("#but_selUnit").click();
        $.bringBack();

    }
</script>
